home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 11 / Amoszine 11 (Disk 2 of 2).adf / Ben_Wyatt_Source.lha / Add_Extension.AMOS / Add_Extension.amosSourceCode
AMOS Source Code  |  2004-04-12  |  3KB  |  137 lines

  1. ' File Extension Adder 
  2. ' ~~~~~~~~~~~~~~~~~~~~ 
  3. ' by Ben Wyatt, bwyatt@paston.co.uk
  4.  
  5. ' Adds an extension to a file, if it has an extension or not 
  6.  
  7. ' Hope all the text stays on a Ntsc screen ;-) 
  8. Screen Open 0,640,256,2,Hires
  9. Screen Display 0,128,37,640,256
  10. Flash Off : Cls 0
  11. Palette $0,$FFF
  12.  
  13. Locate ,2 : Centre "File Extension Adder"
  14. Locate ,3 : Centre "~~~~~~~~~~~~~~~~~~~~"
  15.  
  16. Locate ,6 : Centre 'Type in a file, eg "DH0:Data/Picture"'+" (Doesn't have to exist)"
  17. Put Key "DH0:Data/Picture"
  18. Locate 5,7 : Input "Just here=>";F$
  19.  
  20. Locate ,9 : Centre 'Thats good, now type in an file extension, eg "iff" or "info"'
  21. Put Key "iff"
  22. Locate 3,10 : Input "Type it now=>";X$
  23.  
  24. '    Here it is    
  25. '    ~~~~~~~~~~    
  26. '       *****  
  27. '       *****  
  28. '       *****    
  29. '       *****  
  30. '    *********** 
  31. '     *********  
  32. '      ******* 
  33. '       *****  
  34. '        *** 
  35. '         *  
  36. '
  37. ' WWWWWWWWWWWWWWWWWWW  
  38.  _ADDEXTENSION[F$,X$]
  39. ' MMMMMMMMMMMMMMMMMMM
  40. '
  41. '         *  
  42. '        *** 
  43. '       *****  
  44. '      ******* 
  45. '     *********  
  46. '    *********** 
  47. '       *****  
  48. '       *****  
  49. '       *****    
  50. '       *****  
  51.  
  52. Locate ,12 : Centre "And here they are together"
  53. Locate ,14 : Centre '"'+Param$+'"'
  54. Locate ,16 : Centre "Impressive isn't it?"
  55. Locate ,17 : Centre "Maybe not"
  56. Locate ,19 : Centre "But it does have its uses..."
  57. Locate ,21 : Centre "Press a key"
  58.  
  59. Wait Key 
  60. X$="AxtYpLWqZzz"
  61. F$=Fsel$("","",'Input filename, ensure file ends in ".'+X$+'"',"(See what happens if you don't put it in correctly)")
  62.  
  63. Locate ,21 : Centre "           "
  64. _FILENAME[F$]
  65. Locate 0,21 : Print "Inputted filename:"+Param$
  66.  
  67. _ADDEXTENSION[F$,X$]
  68. _FILENAME[Param$]
  69. Locate 0,23 : Print "New filename:"+Param$
  70.  
  71. Locate ,25 : Centre "Press a key"
  72.  
  73. Wait Key 
  74.  
  75. Edit 
  76.  
  77. Procedure _ADDEXTENSION[F$,X$]
  78.  
  79.    ' Adds file extension X$ to F$, eg F$="Data", X$="s", Param$="Data.s"
  80.    ' Detects if it's already been added, and puts it in the case of X$... 
  81.    '    eg F$="Screen.iff" changes to "Screen.IFF" if X$="IFF"
  82.  
  83.    ' Remove all the comments to make it easier to follow :-)
  84.  
  85.    ' Get rid of the pathname and gets the filename on its own 
  86.    _FILENAME[F$] : FILENAM$=Param$
  87.  
  88.    ' Get rid of the "." in X$ if the user has put one in
  89.    X$=X$-"."
  90.  
  91.    ' Check for the X$ bit and add it if nessassary  
  92.    XPOS=Instr(FILENAM$,"."+X$)
  93.    ' If position of extension is not at the end, ie not at all / in the middle
  94.    If XPOS<>Len(FILENAM$)-1-Len(X$)
  95.       ' If X$ isn't in F$ at all then... 
  96.       If XPOS=0 : XPOS=Instr(FILENAM$,".")
  97.          If XPOS=0
  98.             ' If there's no "." then just add X$ to F$ 
  99.             F$=F$+"."+X$
  100.          Else 
  101.             ' If there's a "." somewhere, put it after that
  102.             F$=Left$(F$,XPOS+(Len(F$)-Len(FILENAM$)))+X$
  103.          End If 
  104.       Else 
  105.          ' Let F$=F$ upto where X$ is included and put it in the case of X$ 
  106.          F$=Left$(F$,XPOS+1)+X$
  107.       End If 
  108.    Else 
  109.       ' Put it in the case of X$ 
  110.       F$=Left$(F$,Len(F$)-Len(X$))+X$
  111.    End If 
  112.  
  113. End Proc[F$]
  114.  
  115. Procedure _BWINSTR[A$,C$]
  116.  
  117.    ' Backwards Instr command/procedure
  118.    ' A$=Input string, C$=Search string
  119.  
  120.    X=Len(A$)
  121.    While Mid$(A$,X,1)<>C$ and X>0
  122.       Dec X
  123.    Wend 
  124.  
  125. End Proc[X]
  126.  
  127. Procedure _FILENAME[F$]
  128.  
  129.    ' Get filename from pathname and filename F$ 
  130.    ' eg. "DH0:Data/Pic.iff" would return "Pic.iff"
  131.  
  132.    ' Get positions of "/" and ":" 
  133.    _BWINSTR[F$,"/"] : SLASH=Param : _BWINSTR[F$,":"] : CLON=Param
  134.    ' Chop out filename
  135.    F$=Right$(F$,Len(F$)-Max(SLASH,CLON))
  136.  
  137. End Proc[F$]